package arithmetic.leetCode.yi;

import java.util.concurrent.atomic.AtomicReference;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yilin
 * Date: 2019-08-12
 * Time: 16:27
 */
public class SigleInstanceV3 {

    private SigleInstanceV3() {
    }

    private static AtomicReference<SigleInstanceV3> INSTANCE = new AtomicReference<>();

    public static SigleInstanceV3 getInstance() {
        for (; ; ) {
            SigleInstanceV3 single = INSTANCE.get();
            if (null != single) {
                return single;
            }
            single = new SigleInstanceV3();
            if (INSTANCE.compareAndSet(null, single)) {
                return single;
            }
        }
    }
}
